{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# C++的数据输入"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. 数据输入"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "① 数据的输入，作用：用于从键盘获取数据。\n",
    "\n",
    "② 数据的输入，关键字：cin\n",
    "\n",
    "③ 数据饿输入，语法：cin >> 变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#include <iostream>\n",
    "using namespace std;\n",
    "#include <string>  //包含string的头文件\n",
    "int main()\n",
    "{\n",
    "\n",
    "    //1、创建bool数据类型\n",
    "    int a = 0;\n",
    "    cout << \"请给整型变量 a 赋值：\" << endl;\n",
    "    cin >> a;\n",
    "    cout << \"整型变量a = \" << a << endl;\n",
    "\n",
    "    //2、浮点型\n",
    "    float f = 3.14f;\n",
    "    cout << \"请给浮点型变量 f 赋值：\" << endl;\n",
    "    cin >> f;\n",
    "    cout << \"浮点型变量 f = \" << f << endl;\n",
    "\n",
    "    //3、字符型\n",
    "    char ch ;  //仅仅声明了，没有初始化\n",
    "    cout << \"请给字符型变量 ch 赋值：\" << endl;\n",
    "    cin >> ch;\n",
    "    cout << \"字符型变量 ch = \" << ch << endl;\n",
    "\n",
    "    //4、字符型\n",
    "    string str = \"hello\";\n",
    "    cout << \"请给字符串 str 赋值：\" << endl;\n",
    "    cin >> str;\n",
    "    cout << \"字符型变量 str = \" << str << endl;\n",
    "\n",
    "    //4、布尔型\n",
    "    bool flag = false;\n",
    "    cout << \"请给布尔类型 flag 赋值：\" << endl;\n",
    "    cin >> flag;   //布尔类型  只要是非0的值都代表真\n",
    "    cout << \"布尔类型 flag = \" << flag << endl;\n",
    "\n",
    "    system(\"pause\");\n",
    "\n",
    "    return 0;\n",
    "\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "运行结果：  \n",
    " - 请给整型变量 a 赋值：\n",
    " - 23\n",
    " - 整型变量a = 23\n",
    " - 请给浮点型变量 f 赋值：\n",
    " - 23.4\n",
    " - 浮点型变量 f = 23.4\n",
    " - 请给字符型变量 ch 赋值：\n",
    " - w\n",
    " - 字符型变量 ch = w\n",
    " - 请给字符串 str 赋值：\n",
    " - asfg\n",
    " - 字符型变量 str = asfg\n",
    " - 请给布尔类型 flag 赋值：\n",
    " - 4562\n",
    " - 布尔类型 flag = 1\n",
    " - 请按任意键继续. . ."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.6.3",
   "language": "python",
   "name": "python3.6.3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
